package io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.tv;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.Command;

/**
 * @author yth
 * @since 2023-04-28-23:21
 */
public class TVOffCommand implements Command {

    private boolean prefixState;
    private final TVReceiver tvReceiver;

    public TVOffCommand(TVReceiver tvReceiver) {
        this.tvReceiver = tvReceiver;
        this.prefixState = tvReceiver.isOn();
    }

    @Override
    public void execute() {
        prefixState = tvReceiver.isOn();
        System.out.println("execute 'tv off' command ...");
        tvReceiver.off();
    }

    @Override
    public void undo() {
        System.out.println("undo 'tv off' command ...");
        tvReceiver.setOn(prefixState);
    }
}
